package com.shiguiwu.springmybatis.spring.async;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

/**
 * @description: 异步执行方法
 * @author: stone
 * @date: Created by 2021/6/11 16:27
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.spring.async
 */
@ComponentScan
@EnableAsync
public class AsyncTests {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AsyncTests.class);
        AsyncService bean = context.getBean(AsyncService.class);
        Future<String> stringFuture = bean.m2();
        System.out.println("===========================================");//最先輸出
        bean.m1();

        System.out.println(stringFuture.get());
    }

}
